<?php
/**
 * Project: HTPHouDuan
 * User: xilibo
 * Date: 2018/1/25
 */

namespace app\api\controller;

use think\Request;
use think\Session;
use app\common\controller\CommonController;

/**
 * 基础控制器
 */
abstract class BaseController extends CommonController
{

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        parent::_initialize();
        $this->curUser = $this->getCurrentUser();
		if(empty($this->curUser)){
            exit($this->jsonError('用户不存在或没登陆')->getContent());
        }
    }

    protected function getCurrentUser()
    {
        $this->curUser['gw_username'] = $this->request->param('gw_username');
        if (! empty($this->curUser['gw_username'])){
            $user = model('user')->getRow(['user_login' => $this->curUser['gw_username']]);
            if (empty($user)){
                return [];
            } else {
                $this->curUser = $user;
            }
        } else if(Session::has('user')){
            $this->curUser = Session::get('user');
        } else {
            return [];
        }

        return $this->curUser;
    }

}
